package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.presenter.contract.SchemeContract;
import com.shd.edanpei.presenter.SchemePresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/4/12.
 * 初审/终审 方案
 */
public class SchemeActivity extends BaseActivity<SchemePresenter>
        implements SchemeContract.SchemeIView {

    @BindView(R.id.headline)
    TextView headline;
    @BindView(R.id.et_scheme_amount)
    EditText etAmount;
    @BindView(R.id.et_scheme_day)
    EditText etDay;
//    @BindView(R.id.et_repayWay)
//    EditText etRepayWay;

    @BindView(R.id.tv_repayWay)
    TextView tvRepayWay;

    private int mOrderId;
    private int mOrderType;
    private int mIndex;
    private int mTag;

    @Override
    protected int setLayout() {
        return R.layout.scheme_details_activity;
    }

    @Override
    protected SchemePresenter bindPresenter() {
        return new SchemePresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        Bundle extras = getIntent().getExtras();
        mOrderId = extras.getInt(Constant.ORDER_ID);
        mOrderType = extras.getInt(Constant.ORDER_TYPE);
        mIndex = extras.getInt(Constant.INDEX);
        mTag = extras.getInt(Constant.TAG);
        switch (mTag) {
            case 0:
                headline.setText("初审方案");
                break;
            case 1:
                headline.setText("终审方案");
                break;
            default:
                break;
        }
    }

    @Override
    protected void initListener() {
        etAmount.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setAmount(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etDay.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setDay(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
//        etRepayWay.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                mPresenter.selectWay(s.toString());
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//
//            }
//        });
    }

    /**
     * 选择利率
     */
    @OnClick(R.id.ll_rate)
    void clickRate() {
        mPresenter.selectRate(R.id.tv_scheme_rate);
    }


    //订单期限
    @OnClick(R.id.ll_date)
    void clickDate() {
        mPresenter.selectData(R.id.tv_scheme_date);
    }

    //归还方式
    @OnClick(R.id.ll_repayWay)
    void onRepayWay() {
        mPresenter.setRepayWay(tvRepayWay);
    }

    @OnClick(R.id.tv_scheme_submit)
    void submit() {
        mPresenter.submit(mTag, mOrderId, mOrderType, mIndex);
    }

    @OnClick(R.id.iv_headline_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void setData(int viewId, String data) {
        TextView view = findViewById(viewId);
        view.setText(data);
        view.setTextColor(ContextCompat.getColor(this, R.color.black));
    }

    @Override
    public void setTextView(TextView view, String str) {
        view.setText(str);
        view.setTextColor(ContextCompat.getColor(this, R.color.black));
    }

}
